#! /bin/bash
pkcs4cj_path=$(cd `dirname $0`; pwd)
#pkcs4cj_path=$(pwd)


# check libcryto.dll
if [ ! -d "${pkcs4cj_path}/lib/" ];then
    mkdir ${pkcs4cj_path}/lib
    echo "Please copy libcryto.dll to the folder ${pkcs4cj_path}/lib."
    exit 1
fi

if [ ! -f "${pkcs4cj_path}/lib/libcrypto.dll" ];then
    echo "Please copy libcryto.dll to the folder ${pkcs4cj_path}/lib."
    exit 1
fi

# pkcs4cj
cd  ${pkcs4cj_path}/
gcc -shared -fPIC ./libpkcs12_c/der_p12.c -o ${pkcs4cj_path}/lib/libderp12.dll
echo start build pkcs4cj
cjpm build -V
cp ${pkcs4cj_path}/lib/*.dll ${pkcs4cj_path}/target/release/pkcs4cj/
echo end build pkcs4cj